package com.gxa.hualianeshop.controller;

import com.gxa.hualianeshop.common.base.R;
import com.gxa.hualianeshop.entity.dto.CartDto;
import com.gxa.hualianeshop.entity.pojo.CartItem;
import com.gxa.hualianeshop.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * @author bill
 * @date 2023/7/21 15:44
 */


@Api("购物车的web接口")
@RestController
@RequestMapping("/cart")
public class CartController {


    @Reference
    private CartService cartService;



    @ApiOperation(value = "添加商品到购物车",notes = "参数: userId,skuId,num")
    @PostMapping("/addItem")
    public R addItem(@RequestBody CartDto cartDto){

        Long userId = cartDto.getUserId();
        Long skuId = cartDto.getSkuId();
        Integer num = cartDto.getNum();
        cartService.addGoodsToCart(userId,skuId,num);
        return R.ok();
    }

    @GetMapping("/getCartItem")
    public R getCartItem(Long userId,Long skuId){
        CartItem cartItem = cartService.queryUserCartItem(userId, skuId);
        System.out.println(cartItem);
        return R.ok(cartItem);
    }

}
